/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-07-20
 * Time: 21:35
 */
public class Test {
    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    public static Object locker3 = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for(int i = 0;i < 10;i++) {
//                synchronized (locker3){
//                    try {
//                        locker3.wait();
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
                System.out.print("A");
                synchronized (locker1) {
                    locker1.notify();
                }
                synchronized (locker3){
                    try {
                        locker3.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 10; i++) {
                synchronized (locker1) {
                    try {
                        locker1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.print("B");
                synchronized (locker2) {
                    locker2.notify();
                }
            }
        });
        Thread t3 = new Thread(()->{
            for(int i = 0;i < 10;i++) {
                synchronized (locker2) {
                    try {
                        locker2.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("C");
                synchronized (locker3) {
                    locker3.notify();
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
//        Thread.sleep(100);
//        synchronized (locker3) {
//            locker3.notify();
//        }
    }
}
